package net.osin.playscalajs.MountPoint

import com.thoughtworks.binding.Binding
import com.thoughtworks.binding.Binding.{SingleMountPoint, Var}
import org.lrng.binding.html
import org.scalajs.dom.html.Div
import org.scalajs.dom.raw.Event

object ViewSMP {
  private val count = Var(0)

  private val count2=Var(0)

  val addCount =
  {
    event: Event =>
      count.value += 1
  }

  val yourCustomMountPoint = new SingleMountPoint[Int ](count) {
    override def mount() = {
      super.mount()
      // Your custom initialization code
    }
    override def unmount() = {
      // Your custom clean up code
      super.unmount()
    }
    override protected def set(newValue: Int):Unit = {
      println("set mounted string",newValue)
      count2.value+=5
      // Your custom handler when `show` get changed
    }

  }


  @html def render:Binding[Div] =
  {
//    yourCustomMountPoint.bind
    <div>
      <h2>监听count的变化,然后改变count2</h2>
      <button onclick={addCount}>addCount</button>
      <p>count={count.bind.toString}</p>
      <p>count2={count2.bind.toString}</p>
    </div>
  }
}
